﻿using Microsoft.AspNetCore.Mvc.Filters;

namespace _51_AOP.Utility.Filter
{
    public class CustomAsyncActionFilterAttribute : Attribute, IAsyncActionFilter
    {
        public async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next)
        {
            Console.WriteLine("---------------------------------------------------");
            var para = context.HttpContext.Request.QueryString.Value;
            var contrallName = context.HttpContext.GetRouteValue("controller");
            var actionName = context.HttpContext.GetRouteValue("action");
            Console.WriteLine($"CustomAsyncActionFilterAttribute 异步Action之间执行,==>{para}---{contrallName}----{actionName}");

            ActionExecutedContext executedContext=await next.Invoke();  //执行action

           var result = Newtonsoft.Json.JsonConvert.SerializeObject(executedContext.Result);
            Console.WriteLine($"CustomAsyncActionFilterAttribute 异步Action之后执行==>{result}");
            Console.WriteLine("---------------------------------------------------");
        }
    }
}
